package com.spring.lesson001.demo3;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;

/**
 * @author vhans
 */
public class UserFactoryBean implements FactoryBean<User1> {
    int count = 1;

    @Override
    public boolean isSingleton() {
        // true为单例,false为多例
        return false;
    }

    @Override
    @Nullable
    public User1 getObject() throws Exception {
        User1 user1 = new User1();
        user1.setName("我是通过Factory创建的第" + count++ + "个对象");
        return user1;
    }

    @Override
    @Nullable
    public Class<?> getObjectType() {
        return User1.class;
    }
}
